# Devin Koepl

# Kbuild

CONTROLLERS=no_controller.o \
	motor_torque_controller.o \
	motor_position_controller.o \
	force_controller.o \
	torque_sine_controller.o \
	position_sine_controller.o \
	openloop_sine_controller.o

obj-m := rtai_controller.o 

rtai_controller-objs := rtai_controller_wrapper.o controller_wrapper_states.o control_switcher_state_machine.o $(CONTROLLERS)

EXTRA_CFLAGS := \
	-I /usr/realtime/include \
	-I $(shell rospack find fca_controllers)/include \
	-I $(shell rospack find fca)/include \
	-I $(shell rospack find drl_library)/include \
	-I $(shell rospack find gui)/include \
	-I /opt/etherlab/include	\
	$(shell rtai-config --module-cflags) \
	-I /usr/include \
	-ffast-math \
	-mhard-float \
	-D COMPILE_FOR_RTAI

KBUILD_EXTRA_SYMBOLS := \
	/usr/src/ethercat-default/Module.symvers \
	/usr/realtime/modules/Modules.symvers \
	/usr/src/linux/Module.symvers

# Makefile

CC = $(shell rtai-config --cc)

LXRT_CFLAGS = $(shell rtai-config --lxrt-cflags)
LXRT_LDFLAGS = $(shell rtai-config --lxrt-ldflags)

LINUX_DIR = $(shell rtai-config --linux-dir)

all: links rtai_controller_wrapper.c
	$(MAKE) -C $(LINUX_DIR) CC=$(CC) SUBDIRS=$$PWD V=$(V) modules

links:
	# Create symbolic links for C++ source files.
	ln -sf ../fca_controllers/src/control_switcher_state_machine.cpp control_switcher_state_machine.c

	ln -sf ../fca_controllers/src/no_controller.cpp no_controller.c
	ln -sf ../fca_controllers/src/motor_torque_controller.cpp motor_torque_controller.c
	ln -sf ../fca_controllers/src/motor_position_controller.cpp motor_position_controller.c
	ln -sf ../fca_controllers/src/force_controller.cpp force_controller.c
	ln -sf ../fca_controllers/src/torque_sine_controller.cpp torque_sine_controller.c
	ln -sf ../fca_controllers/src/position_sine_controller.cpp position_sine_controller.c
	ln -sf ../fca_controllers/src/openloop_sine_controller.cpp openloop_sine_controller.c


install:
	insmod rtai_controller.ko

uninstall:
	rmmod rtai_controller.ko

clean:
	$(RM) $(LINUX_DIR)/.tmp_versions/*_rt.mod *.o *.ko *.mod.c .*.cmd Module.symvers modules.order
